package de.herberlin.webapp.text.action;

import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import de.herberlin.webapp.core.AbstractAction;
import de.herberlin.webapp.core.AppException;
import de.herberlin.webapp.db.Service;
import de.herberlin.webapp.text.Page;

public class DeleteTextAction extends AbstractAction {

	private static final long serialVersionUID = 1L;

	@DefaultHandler
	public Resolution delete() {

		String pageId = getPageId();
		logger.debug("PageId=" + pageId);
		Page page = Service.getItem(Page.class, pageId);
		if (page == null) {
			throw new AppException("Page not found for PageId:" + pageId);
		}
		page.setText(null);
		Service.persist(page);
		logger.debug("Page: " + page + " successfully deleted.");

		return new RedirectResolution(getUrl(page));
	}

}
